-- $Id: init.lua 47 2008-07-11 23:07:35Z dtikhonov $
--
-- Initialization functions

--
-- This function will be called when the bookmarks section of the
-- file-specific config is processed, e.g.
-- 
-- bookmarks {
--     { name = "dude", location = 0x12C0 },
-- }
--
function bookmarks (obj)
    if ("nil" == type(_bookmarks)) then
        error("Global variable `_bookmarks' is not set")
    end

    if ("table" ~= type(obj)) then
        io.stderr:write("`bookmarks' should be a table\n")
        return false
    end

    for i in pairs(obj) do
        _bookmarks:add(obj[i].name, obj[i].location)
    end
end

function save_state (file)
    if ("nil" == type(file)) then
        error("File is not specified")
    end

    local fh = io.open(file, "w")
    _bookmarks:serialize(fh)
end

-- Initialize global variables:
_bookmarks = Bookmarks:new()
